import { defineStore } from 'pinia'
import { Names} from './store-name'


type User ={
 name:string,
 age:number
}
// 同步
// let result:User = {
//     name:"周杰伦",
//     age:999
// }

// 异步
const Login = ():Promise<User> => {
 return new Promise((resolve)=>{
  setTimeout(()=>{
      resolve({
        name:"周杰伦",
        age:999
      })
  },500)
 })
}

export const useTestStore =defineStore(Names.TEST,{
    state:()=>{
        return{
            current:1,
            name:'邓紫棋987456211',
            user:<User>{},
            age:''
        }
    },
    // computed 修饰一些值
    getters :{
        newName ():string {
            return this.name
        }

    },
    // methods 可以做同步,异步都可以做,提交state
    actions :{
        async setCurrent(){
            // this.current =122
            // 同步
            // this.user =result
            // 异步
             const result = await Login()
             this.user =result
        }

    }
})